package cn.declare.controller.talent;


import cn.declare.bean.talent.Talentdemand;
import cn.declare.bean.variation.Variation;
import cn.declare.service.talent.TalentService;
import cn.declare.vo.talent.TalentdemandVo;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * author 岳静贤
 * 人才情况controller层
 */
@RestController
@RequestMapping("/talent")
@Slf4j
public class TalentController {

    @Resource
    private TalentService talentService;

    /**
     * 获取全部人才类型
     * @return Json类型的集合
     */
    @GetMapping("/talentselect")
    public String getTalentType(){
        return JSON.toJSONString(talentService.getTalentType());
    }

    /**
     * 根据人才类型获取到该类型数据，根据id从大到小排序
     * @param employeetype
     * @return Json类型的集合
     */
    @GetMapping("/ordinary/{employeetype}")
    public String getFindByType(@PathVariable("employeetype") Integer employeetype){
        return JSON.toJSONString(talentService.getFindByType(employeetype));
    }

    @GetMapping("/ordinarys/{employeetype}")
    public String getFindByState(@PathVariable("employeetype") Integer employeetype){
        return JSON.toJSONString(talentService.getFindByState(employeetype));
    }

    @PostMapping("/add")
    public int getTalentAdd(@RequestBody TalentdemandVo talentdemandVo){
        int talentAdd = talentService.getTalentAdd(talentdemandVo);
        return talentAdd;
    }

    @GetMapping("/findAll")
    public List<TalentdemandVo> getFindAll(){
        List<TalentdemandVo> findAll = talentService.getFindAll();
        return findAll;
    }

    @GetMapping("/findTalent4")
    public List<Talentdemand> getFindByTalentType(){
        List<Talentdemand> findByTalentType = talentService.getFindByTalentType();
        return findByTalentType;
    }

    @GetMapping("/findById/{id}")
    public TalentdemandVo getFindById(@PathVariable("id") Integer id){
        TalentdemandVo findById = talentService.getFindById(id);
        return findById;
    }

    @PutMapping("/update/{id}")
    public void getUpdate(@RequestBody TalentdemandVo talentdemandVo){
        int update = talentService.getUpdate(talentdemandVo);
        TalentdemandVo vo = new TalentdemandVo();
        System.out.println(update);
    }

    @PutMapping("/updateNeed/{id}")
    public void getUpdateNeed(@RequestBody TalentdemandVo talentdemandVo){
        int updateNeed = talentService.getUpdateNeed(talentdemandVo);
    }

    @GetMapping("/findNeed/{id}")
    public TalentdemandVo getFindNeed(@PathVariable("id") Integer id){
        TalentdemandVo findById = talentService.getFindNeed(id);
        return findById;
    }

    @GetMapping("/needs/{id}")
    public TalentdemandVo getNeeds(@PathVariable("id") Integer id){
        TalentdemandVo need = talentService.getNeed(id);
        return need;
    }

    //审批未通过，填报页面需要修改， 此方法为修改中的查看
    @GetMapping("/putong/{employeetype}")
    public TalentdemandVo getPutongTalent(@PathVariable("employeetype") Integer employeetype){
        TalentdemandVo putongTalent = talentService.getPutong(employeetype);
        return putongTalent;
    }

    @GetMapping("/jixu/{employeetype}")
    public TalentdemandVo getJixu(@PathVariable("employeetype") Integer employeetype){
        TalentdemandVo jixu = talentService.getJixu(employeetype);
        return jixu;
    }

    @PutMapping("/putong/update")
    public void getPutongUpdate(@RequestBody TalentdemandVo talentdemandVo){
        int putongUpdate1 = talentService.getPutongUpdate(talentdemandVo);
    }

    @PutMapping("/jixu/update")
    public void getJiXuUpdate(@RequestBody TalentdemandVo talentdemandVo){
        int putongUpdate1 = talentService.getJiXuUpdate(talentdemandVo);
    }

    @GetMapping("/variation")
    public List<Variation> getVariaion(){
        List<Variation> variation = talentService.getVariation();
        return variation;
    }

    @GetMapping("/date")
    public List<Talentdemand> getDate(@Param("startDate") String startDate,
                                     @Param("lastDate")  String lastDate) throws ParseException {
        log.info("时间为：{}",startDate);
        log.info("时间为：{}",lastDate);
        DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = dateFormat1.parse(startDate);
        Date parse1 = dateFormat1.parse(lastDate);
        List<Talentdemand> findByCreatDate = talentService.getFindByCreatDate(parse,parse1);
        return findByCreatDate;
    }

    @GetMapping("/date02")
    public List<Talentdemand> getDate02(@Param("startDate") String startDate,
                                        @Param("lastDate")  String lastDate) throws ParseException {
        DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = dateFormat1.parse(startDate);
        Date parse1 = dateFormat1.parse(lastDate);
        List<Talentdemand> findByCreatDate = talentService.getFindByCreatDate02(parse,parse1);
        return findByCreatDate;
    }

}
